<?php
namespace app\common\controller;

use think\auth\Auth;
use think\Loader;
use think\Controller;

/**
* 商家后台公用基础控制器
* @author Kaisa
* @version 2017-02-09
*/
class AllianceBaseController extends Controller {
	
    protected function _initialize() {
        parent::_initialize();
		
        $store_id = session('storeInfo')['id'];
        if (empty($store_id)) {
            $this->redirect('union/login/index');
        }
		
		// 当前路径URL，菜单用到
		$this->assign('current_url', Loader::parseName(request()->controller()));
		
        $this->getMenu();
		
    }

  
    /**
     * 获取侧边栏菜单
     */
    protected function getMenu() {
        $menu     = [];
        $store_id = session('storeInfo')['id'];
        $auth     = new Auth();
		$where['status'] = 1;
        $auth_rule_list = db('store_menu')->where($where)->order(['sort' => 'asc', 'id' => 'asc'])->select();
	    foreach ($auth_rule_list as $value) {
			$menu[] = $value;
        }
        $menu = !empty($menu) ? array2tree($menu) : [];
        $this->assign('menu', $menu);
    }
}
